package com.ophiux.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ophiux.common.core.utils.R;
import com.ophiux.common.security.annotation.Inner;
import com.ophiux.system.model.entity.SysUser;
import com.ophiux.system.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
@RequestMapping("/user")
@Api(tags = "用户管理模块")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class SysUserController {

	private final SysUserService userService;

	/**
	 * 获取指定用户全部信息
	 * @return 用户信息
	 */
	@GetMapping("/info/{username}")
	@Inner
	public R info(@PathVariable String username) {
		SysUser user = userService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, username));
		if (user == null) {
			return R.failed("未找到用户信息");
		}
		return R.ok(userService.findUserInfo(user));
	}

}
